//
//  MRNestTableViewCell.m
//  MRDemo
//
//  Created by dingping on 2020/8/18.
//  Copyright © 2020 dingping. All rights reserved.
//

#import "MRNestTableViewCell.h"
#import "MyLayout.h"

@interface MRNestTableViewCell ()

@property (nonatomic, strong) UIImageView *goodsCoverImgView;
@property (nonatomic, strong) UIImageView *goodsImgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIImageView *iconImgView;

@end


@implementation MRNestTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = Main_BG_color;
        [self setupSubViews];
    }
    return self;
}


- (void)setupSubViews
{
    MyRelativeLayout *layout = [MyRelativeLayout new];
    layout.myTop = 15;
    layout.myBottom = 0;
    layout.myLeft = layout.myRight = 15;
    layout.layer.cornerRadius = 8;
    layout.layer.masksToBounds = YES;
    layout.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:layout];
    
    [layout addSubview:self.goodsCoverImgView];
    
    [layout addSubview:self.titleLabel];
    [layout addSubview:self.iconImgView];
    [layout addSubview:self.timeLabel];
    [layout addSubview:self.goodsImgView];
    
    _goodsCoverImgView.myTop = 62;
    _goodsCoverImgView.myLeft = 10;
    _goodsCoverImgView.mySize = CGSizeMake(kScreenW-50, 216);
    
    _timeLabel.myLeft = 10;
    _timeLabel.myTop = 8;
    
    _titleLabel.myLeft = 10;
    _titleLabel.topPos.equalTo(_timeLabel.bottomPos).offset(3);
    _titleLabel.myRight = 10;
    
    _iconImgView.myLeft = 18;
    _iconImgView.topPos.equalTo(_goodsCoverImgView).offset(8);

    _goodsImgView.myRight = 22;
    _goodsImgView.myBottom = 22;
    
}

- (UIImageView *)goodsCoverImgView {
    if(!_goodsCoverImgView) {
        _goodsCoverImgView = [[UIImageView alloc]init];
        _goodsCoverImgView.layer.cornerRadius = 8;
        _goodsCoverImgView.layer.masksToBounds = YES;
        _goodsCoverImgView.contentMode = UIViewContentModeScaleAspectFill;
        _goodsCoverImgView.image = [UIImage imageNamed:@"cover"];
    }
    return _goodsCoverImgView;
}

- (UIImageView *)goodsImgView {
    if(!_goodsImgView) {
        _goodsImgView = [[UIImageView alloc]init];
        _goodsImgView.layer.cornerRadius = 4;
        _goodsImgView.layer.masksToBounds = YES;
        _goodsImgView.mySize = CGSizeMake(50, 50);
    }
    return _goodsImgView;
}

- (UIImageView *)iconImgView {
    if(!_iconImgView) {
        _iconImgView = [[UIImageView alloc]init];
        _iconImgView.backgroundColor = [UIColor cyanColor];
    }
    return _iconImgView;
}


- (UILabel *)titleLabel {
    if(!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        _titleLabel.text = @"测试测试测试哈哈";
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

- (UILabel *)timeLabel {
    if(!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = [UIFont systemFontOfSize:16];
        _timeLabel.textColor = [UIColor grayColor];
        _timeLabel.text = @"08月18日 19:00";
        [_timeLabel sizeToFit];
    }
    return _timeLabel;
}

@end
